﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using WpfApplication5.Models;

namespace WpfApplication5.ViewModels
{
    public class FunctionInfoViewModel:TreeViewItemViewModel
    {
        readonly FuncationInfo _info;
        readonly SQLiteDatabase _db;
        ObservableCollection<FunctionParameter> _parameters;
        ICommand _sampleCommand;
        string _selectedSample;

        public FunctionInfoViewModel(FuncationInfo info,FunctionCategoryViewModel parent,SQLiteDatabase db)
            :base(parent,false)
        {
            this._info = info;
            this._db = db;
        }
        public FuncationInfo FunctionInfo
        {
            get { return _info; }
        }
        public string SelectedSample
        {
            get { return _selectedSample; }
            set
            {
                _selectedSample = value;
                OnPropertyChanged(() => this.SelectedSample);
            }
        }
        public ObservableCollection<FunctionParameter> Parameters
        {
            get
            {
                if (_parameters == null)
                {
                    _parameters = new ObservableCollection<FunctionParameter>(_db.GetParameters(this.FunctionInfo.ParameterId));
                }
                return _parameters;
            }
            set
            {
                _parameters = value;
                OnPropertyChanged(() => this.Parameters);
            }
        }
        
       
        public ICommand SampleCommand
        {
            get
            {
                if (_sampleCommand == null)
                {
                    _sampleCommand = new RelayCommand(_ => MessageBox.Show(SelectedSample));
                }
                return _sampleCommand;
            }
        }
    }
}
